package com.grep.extra.dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.grep.base.db.DBUtils;
import com.grep.base.util.PinYin4jUtil;
import com.grep.base.util.UUIDGenerator;
import com.grep.extra.dao.BaseDao;

public class ContentParseDao {

	BaseDao baseDao = new BaseDaoImpl();

	// 添加
	public boolean addContentParse(String taskname) {

		TaskDAOSQL taskDao = new TaskDAOSQL();

		String id = UUIDGenerator.getUUID();
		String taskid = taskDao.getIdByTaskName(taskname);
		String taskenname = PinYin4jUtil.getPinyin(taskname);

		String insertSql = "insert into content_parse(id,task_id,content_parse_tablename) values('"
				+ id + "','" + taskid + "','" + taskenname + "')";

		return baseDao.insert(insertSql);
	}

	public String getIdforTaskId(String taskid) {

		Connection conn = null;
		Statement stat = null;
		ResultSet result = null;

		String id = "";

		String selectSql = "select id from content_parse where task_id='"+taskid+"'";

		try {
			conn = DBUtils.getConnection();
			stat = conn.createStatement();
			result = stat.executeQuery(selectSql);
			if (result.next()) {
				id = result.getString("id");
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DBUtils.close(result);
			DBUtils.close(stat);
			DBUtils.close(conn);
		}

		return id;
	}
}
